/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.openbookformat.tags;

/**
 *
 * @author MUFEED
 */
public class WidthAttr {
    public static final int PERCENTAGE = 0;
    public static final int PIXEL      = 1;
    public static final int CM         = 2;

    private double width;
    private int type;

    public WidthAttr(double width, int type) {
        this.width = width;
        this.type = type;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public static WidthAttr parseWidthAttr(String text) {
        int type = -1;
        double width = -1;
        if(text.contains("%")) {
            type = PERCENTAGE;
            width = Double.parseDouble(text.substring(0, text.indexOf("%")));
        } else if(text.contains("cm")) {
            type = CM;
            width = Double.parseDouble(text.substring(0, text.indexOf("cm")));
        } else if(text.contains("px")) {
            type = PIXEL;
            width = Double.parseDouble(text.substring(0, text.indexOf("px")));
        }
        return new WidthAttr(width,type);
    }
}
